import request from '@/utils/request'
import { RootThunkAction } from '..'
/**
 * 获取文章详情信息
 * @param id
 * @returns
 */
export const getArticleDetails = (id: string): RootThunkAction => {
  return async (dispatch) => {
    const res = await request({
      method: 'GET',
      url: `articles/${id}`,
    })
    // console.log(res)
    dispatch({
      type: 'article/saveArticleDetails',
      payload: res.data,
    })
  }
}
/**
 * 获取评论数据
 */
export const getCommentList = (id: string): RootThunkAction => {
  return async (dispatch) => {
    const res = await request({
      method: 'GET',
      url: '/comments',
      params: {
        type: 'a',
        source: id,
      },
    })
    // console.log(res)
    dispatch({
      type: 'article/saveComment',
      payload: res.data,
    })
  }
}
